package com.hcyy.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hcyy.dao.CustOrderDao;
import com.hcyy.dao.UserDao;
import com.hcyy.entity.CustOrder;
import com.hcyy.entity.User;
import com.hcyy.service.UserService;
import com.hcyy.util.MD5Util;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;
	@Autowired
	private CustOrderDao custOrderDao;
	@Override
	public boolean login(User user,Integer sjid) {
		boolean tag=false;
		User u=userDao.findUserByUserName(user.getUsername(), sjid);
		if(null!=u){
			if(u.getPassword().equals(MD5Util.string2MD5(user.getPassword()))){
				tag=true;
			}
		}
		return tag;
	}

	@Override
	public Map<String,Integer> countOrder(String dwbh, Integer sjid){
		List<CustOrder> orderList=custOrderDao.findAllOrders(dwbh, sjid);
		int upCnt=0;//代付款
		int udCnt=0;//待发货
		int idCnt=0;//已发货
		for(CustOrder order:orderList){
			byte isPay=order.getIsPay();
			byte isDeliver=order.getIsDeliver();
			if(isPay==0&&isDeliver==0){
				upCnt+=1;
			}
			if(isPay==1&&isDeliver==0){
				udCnt+=1;
			}
			if(isPay==1&&isDeliver==1){
				idCnt+=1;
			}
		}
		Map<String,Integer> map=new HashMap<String,Integer>();
		map.put("upCnt", upCnt);
		map.put("udCnt", udCnt);
		map.put("idCnt", idCnt);
		return map;
	}
}
